<?php include '../../authorization_check.php' ?>
<?php include '../../checkSecretaryOnly.php' ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>Add staff</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>
<SCRIPT TYPE="text/javascript" >
 function staffControl(){
   var myForm = document.form1;
   /* alert("xxx"); */
   if (textboxControl(myForm.personnelID.value) && textboxControl(myForm.personnelName.value) && textboxControl(myForm.personnelSurname.value))
   {
		return true;
   }
   else{
      alert("Personnel ID, name and surname must be filled.");
      return false;
   }
    
 }
 

</SCRIPT>
</head>
<style type="text/css">
th {text-align: right}
</style>
<body>
<?php include 'top.html' ?>

<p>
Please enter staff details to record the new staff to the system.
</p>

  
<FORM NAME ="form1" METHOD ="POST" ACTION = "AddStaff.php">
<?php
require_once '../../commonutils/db/DBConnectionManager.php';

if (isset($_POST['btnSubmit']))
{
	$personnelID = $_POST['personnelID'];
	$personnelName = strtoupper($_POST['personnelName']);
	$personnelSurname = strtoupper($_POST['personnelSurname']);
	$citizenship = $_POST['citizenship'];
	$birthPlace = strtoupper($_POST['placeOfBirth']);
	
	$birthDate = $_POST['byyyy']."-".$_POST['bmm']."-".$_POST['bdd'];
	$employmentDate = $_POST['eyyyy']."-".$_POST['emm']."-".$_POST['edd'];

	$title = $_POST['title'];
	
	if($title == "Assistant" || $title == "Administrative" ){
		$sqlquery = "insert into personnel(personnelID, firstName, lastName, title, TC_Kimlik, DateOfBirth, PlaceOfBirth, EmploymentDate) values"
				."(".$personnelID.", '".$personnelName."', '".$personnelSurname."', '".$title."',".$citizenship.", '".$birthDate."','".$birthPlace."','".$employmentDate."')" ;
		$result = DBConnectionManager::query($sqlquery);		
	}
	else
	{
		$sqlquery = "insert into instructor(instructorID, firstName, lastName, title, TC_Kimlik, DateOfBirth, PlaceOfBirth, EmploymentDate) values"
				."(".$personnelID.", '".$personnelName."', '".$personnelSurname."', '".$title."',".$citizenship.", '".$birthDate."','".$birthPlace."','".$employmentDate."')" ;
		$result = DBConnectionManager::query($sqlquery);	
	}
	

	// echo $sqlquery; 
	$result = DBConnectionManager::query($sqlquery);
	//$row = mysql_fetch_assoc($result);
	echo "<p><font color=blue><b>You have successfully added ".$personnelName." ".$personnelSurname." to the system.</b></font></p>";

}

?>

<table>
<tr>
<td>Personnel ID: </td>
<td><input type="text" name="personnelID" size="12" maxlength=11 onKeyPress="return numbersonly(this, event)"/></td>
</tr>
<td>Name: </td>
<td><input type="text" style="text-transform: uppercase" name="personnelName" size="20" /></td>
</tr>
<td>Surname: </td>
<td><input type="text" style="text-transform: uppercase" name="personnelSurname" size="20" /></td>
</tr>
<td>Citizenship Number: </td>
<td><input type="text" name="citizenship" size="12" maxlength=11 onKeyPress="return numbersonly(this, event)"/></td>
</tr>
<td>Date of birth: </td>
<td>
		<select name="bdd" > 
			<option value="01">1</option>
			<option value="02">2</option>
			<option value="03">3</option>
			<option value="04">4</option>
			<option value="05">5</option>
			<option value="06">6</option>
			<option value="07">7</option>
			<option value="08">8</option>
			<option value="09">9</option>
			<option value="10">10</option>
			<option value="11">11</option>
			<option value="12">12</option>
			<option value="13">13</option>
			<option value="14">14</option>
			<option value="15">15</option>
			<option value="16">16</option>
			<option value="17">17</option>
			<option value="18">18</option>
			<option value="19">19</option>		
			<option value="20">20</option>
			<option value="21">21</option>
			<option value="22">22</option>
			<option value="23">23</option>
			<option value="24">24</option>
			<option value="25">25</option>
			<option value="26">26</option>
			<option value="27">27</option>
			<option value="28">28</option>
			<option value="29">29</option>
			<option value="30">30</option>
			<option value="31">31</option>						
		</select>
		 /
		<select name="bmm" > 
			<option value="01">January</option>
			<option value="02">February</option>
			<option value="03">March</option>
			<option value="04">April</option>
			<option value="05">May</option>
			<option value="06">June</option>
			<option value="07">July</option>
			<option value="08">August</option>
			<option value="09">September</option>
			<option value="10">October</option>
			<option value="11">November</option>
			<option value="12">December</option>
		</select>
		/
		<input type="text" name="byyyy" size="4" onKeyPress="return numbersonly(this, event)"/>
</td>


</td>
</tr>
<td>Place of birth: </td>
<td><input type="text" style="text-transform: uppercase" name="placeOfBirth" size="20" /></td>
</tr>
<td>Employment date : </td>
<td>
		<select name="edd" > 
			<option value="01">1</option>
			<option value="02">2</option>
			<option value="03">3</option>
			<option value="04">4</option>
			<option value="05">5</option>
			<option value="06">6</option>
			<option value="07">7</option>
			<option value="08">8</option>
			<option value="09">9</option>
			<option value="10">10</option>
			<option value="11">11</option>
			<option value="12">12</option>
			<option value="13">13</option>
			<option value="14">14</option>
			<option value="15">15</option>
			<option value="16">16</option>
			<option value="17">17</option>
			<option value="18">18</option>
			<option value="19">19</option>		
			<option value="20">20</option>
			<option value="21">21</option>
			<option value="22">22</option>
			<option value="23">23</option>
			<option value="24">24</option>
			<option value="25">25</option>
			<option value="26">26</option>
			<option value="27">27</option>
			<option value="28">28</option>
			<option value="29">29</option>
			<option value="30">30</option>
			<option value="31">31</option>						
		</select>
		 /
		<select name="emm" > 
			<option value="01">January</option>
			<option value="02">February</option>
			<option value="03">March</option>
			<option value="04">April</option>
			<option value="05">May</option>
			<option value="06">June</option>
			<option value="07">July</option>
			<option value="08">August</option>
			<option value="09">September</option>
			<option value="10">October</option>
			<option value="11">November</option>
			<option value="12">December</option>
		</select>
		/
		<input type="text" name="eyyyy" size="4" onKeyPress="return numbersonly(this, event)"/>
</td>
</tr>
<td>Title: </td>
<td>
<select name="title" size="6" />
	<option value="Prof. Dr." selected>Prof. Dr.</option>
	<option value="Assoc. Prof. Dr.">Assoc. Prof. Dr.</option>
	<option value="Assist. Prof. Dr.">Assist. Prof. Dr.</option>
	<option value="Dr.">Dr.</option>
	<option value="Instr.">Instr.</option>
	<option value="Assistant">Assistant</option>
	<option value="Administrative">Administrative</option>
</select>	
</td>
</tr>
</table>
<input type="submit" value="Record the staff" name="btnSubmit" onClick="return staffControl()">
<input type="reset" value="Reset fields" name="btnReset">
</FORM>


<?php include 'bottom.php' ?>

</body>
</html>


